package com.fxcalibre.utils;

import java.io.File;
import java.io.FilenameFilter;
import java.util.ArrayList;
import java.util.List;


public class FileUtils
{
	
	public static File getImgsDir()
	{
		String imgDirStr = (String) Preferences.getPreferences().get(Constants.KEY_DB_FILE) + "/db/imgs/";
		File imgDir = new File(imgDirStr);
		System.out.println("imgDir: " + imgDir.getAbsolutePath());
		if (!imgDir.exists())
		{
			System.out.println("Creando directorio");
			imgDir.mkdir();
		}
		
		return imgDir;
	}

	public static List<File> getFiles(File dir)
	{
		List<File> results = new ArrayList<File>();
		System.out.println("dir Exist: " + dir);
		if (dir.exists())
		{
			System.out.println("existe");
			File[] files = dir.listFiles(new MediaFilenameFilter());
			for (int i = 0; files != null && i < files.length; i++)
			{

				results.add(files[i]);
			}

			File[] directories = dir.listFiles(new FilenameFilter()
			{
				@Override
				public boolean accept(File file, String name)
				{
					return file.isDirectory();
				}
			});

			for (int i = 0; directories != null && i < directories.length; i++)
			{
				results.addAll(getFiles(directories[i]));
			}
		}
		return results;
	}
	

	public static void main(String[] args)
	{
		File dir = new File("H:\\Media\\Pelis");
		System.out.println(getFiles(dir));
	}
}
